import 'package:flutter/material.dart';
import 'package:voice_tx/model/User.dart';

class UserDrawer extends StatelessWidget {
  final User user;

  UserDrawer(this.user);

  @override
  Widget build(BuildContext context) {
    Map<String, dynamic> json = user.toJson();
    json.remove('avatar');
    json.remove('realname');
    List<Widget> list = <Widget>[
      new UserAccountsDrawerHeader(
          accountEmail: new Text('email'),
          accountName: Padding(
            padding: const EdgeInsets.only(left: 8.0),
            child: new Text(user.realname),
          ),
          currentAccountPicture: user.avatar != null
              ? new CircleAvatar(
                  backgroundImage: new NetworkImage(user.avatar),
                )
              : new CircleAvatar(
                  child: new Text(user.realname),
                ))
    ];
    json.keys.forEach((key) {
      var value = json[key];
      list.add(new ListTile(
        title: new Text('$key : $value'),
      ));
    });
    return new Listener(
      child: new Container(
          constraints: new BoxConstraints(
              minHeight: MediaQuery.of(context).size.height,
              maxWidth: MediaQuery.of(context).size.width - 100),
          child: new Material(
            child: new Column(
              children: list,
            ),
          )),
      onPointerUp: (event) {
        print('drawer on pointer Up');
      },
    );
  }
}
